// JavaScript Document

// Date: 2014-11-07
// Author: Fan Xu
i = 0;
j = 0;
count = 0;
MM = 0;
SS = 60;  // 绉� 90s
MS = 0;
totle = (MM+1)*600;
d = 180*(MM+1);
MM = "0" + MM;
var is_ajax=false;
var anim_timer = (function () {
    var sh  = screen.width;
    var wh = sh*0.9;
    if(sh>1024){return {
        width:wh+'px',
        height:'640px',
        left:'2.5%',
        top:'15%',
        opacity: 1
    }}
    else{return {
        width:'850px',
        height:'640px',
        left:'5%',
        opacity: 1
    }}
}());

//count down
var showTime = function(){
    totle = totle - 1;
    if (totle == 0) {
        clearInterval(s);
        clearInterval(t1);
        // clearInterval(t2);
        $(".pie2").css("-o-transform", "rotate(" + d + "deg)");
        $(".pie2").css("-moz-transform", "rotate(" + d + "deg)");
        $(".pie2").css("-webkit-transform", "rotate(" + d + "deg)");

    } else {
        if( totle == 10 ){
            FX.Prize.randPrize();
        }
        if (totle > 0 && MS > 0) {
            MS = MS - 1;
            if (MS < 10) {
                MS = "0" + MS
            }
            ;
        }
        ;
        if (MS == 0 && SS > 0) {
            MS = 10;
            SS = SS - 1;
            if (SS < 10) {
                SS = "0" + SS
            }
            ;
        }
        ;
        if (SS == 0 && MM > 0) {
            SS = 60;
            MM = MM - 1;
            if (MM < 10) {
                MM = "0" + MM
            }
            ;
        }
        ;
    }
    ;
    $(".time").html(SS);

};

var start1 = function(){
    var gameTime = FX.Prize.shake_second;
    //i = i + 0.6;
    i = i + 360/((gameTime)*10);  //鏃嬭浆鐨勮搴�  90s 涓� 0.4  60s涓�0.6
    count = count + 1;
    if(count <= (gameTime/2*10)){  // 涓€鍗婄殑瑙掑害  90s 涓� 450
        $(".pie1").css("-o-transform","rotate(" + i + "deg)");
        $(".pie1").css("-moz-transform","rotate(" + i + "deg)");
        $(".pie1").css("-webkit-transform","rotate(" + i + "deg)");
    }else{
        $(".pie2").css("backgroundColor", "#d13c36");
        $(".pie2").css("-o-transform","rotate(" + i + "deg)");
        $(".pie2").css("-moz-transform","rotate(" + i + "deg)");
        $(".pie2").css("-webkit-transform","rotate(" + i + "deg)");
    }
};

/**
 * 绂荤嚎鎶藉
 */
var countDown = function() {
    var gameTime = FX.Prize.shake_second;
    //80*80px 鏃堕棿杩涘害鏉�
    i = 0;
    j = 0;
    count = 0;
    MM = 0;
    SS = gameTime;
    MS = 0;
    totle = (MM + 1) * gameTime * 10;
    d = 180 * (MM + 1);
    MM = "0" + MM;

    showTime();

    s = setInterval("showTime()", 100);
    start1();
    //start2();
    t1 = setInterval("start1()", 100);
}
var startRoll = function(){
    var btn = $('.g-button-red');

    if(btn.hasClass('disabled'))
        return;

    btn.addClass('disabled');
    FX.Prize.displayEffect = function(){
        var html = '';
        $.each(FX.Prize.current_prize_persons ,function(k,v){
            html += '<li class="reward-item"><img src="'+v.avatar+'"><p>'+v.nickname+'</p></li>';
        } );
        $('.reward-wrap').find('ul').html(html);
        //闃叉闈炴鏂瑰舰鍥剧墖
        jQuery.each($('.reward-wrap img'),function(i,n){
            var h = $(n).width();console.log(h + 'px');
            if(h)
                $(n).height(h);
        });
        $('#countdown').fadeOut(500,function(){
            $('.printbox')
                .show()
                .animate(anim_timer, 1500,function(){

            });
        });
        FX.Prize.endedRoll();
    }
    FX.Prize.startRoll();
    $('#countdown').fadeIn(700);
    countDown();
}